package event;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.w3c.dom.Document;

import parallel.BasicRangeInputSplit;

abstract public class Generator {
	protected Document config = null;
	protected int numOfRegions;
	protected int mode = 0;
	protected PageConfig nodeConfig = null;
	protected BasicConfig basicConfig = null;
	protected EventConfig eventConfig = null;
	protected BasicRangeInputSplit inputSplit = null;
	protected Map<String, AttrGenerator> attrGenerators = null;
	public Generator(int numOfRegions, BasicRangeInputSplit inputSplit)
	{
		this.numOfRegions = numOfRegions;
		this.inputSplit = inputSplit;
		attrGenerators = new HashMap<String, AttrGenerator>();
		nodeConfig = new PageConfig();
		basicConfig = new BasicConfig();
		eventConfig = new EventConfig();
		mode = eventConfig.getSequence().getMode();
		loadAttrGenerators();
	}
	// Initialize the list of attribute generators
	abstract public void generate(long inputKey, String inputValue) throws IOException, InterruptedException;
	private void loadAttrGenerators()
	{
		if(mode == 1)
		{
		    attrGenerators.put("Reference", new ReferenceAttrGenerator(numOfRegions,inputSplit.getSplitId()));
		}
		else
		{
			attrGenerators.put("Reference", new ReferenceAttrGenerator(1,0));
		}	
		attrGenerators.put("Database", new DBAttrGenerator());
		attrGenerators.put("Long", new LongAttrGenerator());
		attrGenerators.put("String", new StringAttrGenerator());
	}
	
}
